function ShowModal(e, d, i) {
    $("#" + e).find(".modal-title").html(d), $("#" + e).find(".modal-footer").html(i), $(".modal-back").show(), $("#" + e).show().css({
        "margin-top": -$("#" + e).height() / 2,
        "margin-left": -$("#" + e).width() / 2
    }), $(".modal-close").click(function () {
        HideModal(e)
    })
}
function HideModal(e) {
    $(".modal-back").hide(), $("#" + e).hide()
}
function ShowModalUrl(e, d, i, t, a, r) {
    $(".modal-back").show();
    var o = $(".modal-back").height();
    r > o - 80 && (r = o - 80);
    var n = $(".modal-back").width();
    a > n - 10 && (a = n - 10), $("#" + e).find(".modal-body").html("<iframe style='border-width:0px;width:" + a + "px;height:" + r + "px''  frameborder='0' src='" + d + "' ></iframe>"), ShowModal(e, i, t)
}
function BindMoveModal() {
    $model = $("table.modal"), $modelHead = $model.find("td.modal-title");
    var e = !1, d = null, i = 0, t = 0, a = null;
    $modelHead.bind("mousedown", function (d) {
        i = d.clientX, t = d.clientY, e = !0, a = $(this).closest("table.modal"), a && a.find(".modal-body-shade").show()
    }), $("body").bind("mouseup", function () {
        e = !1, a && a.find(".modal-body-shade").hide()
    }), $("body").bind("mouseleave", function () {
        e = !1, a && a.find(".modal-body-shade").hide()
    }), $("body").bind("mousemove", function (r) {
        null == d && 0 != e && (d = setTimeout(function () {
            var e = r.clientX - i, o = r.clientY - t, n = parseInt(a.css("marginTop")), l = parseInt(a.css("marginLeft"));
            i = r.clientX, t = r.clientY, a && a.css({
                marginTop: n + o + "px",
                marginLeft: l + 1.5 * e + "px"
            }), d = null
        }, 20))
    })
}
function add() {
    var e = "";
    e = arguments.length > 0 && "" != arguments[0] ? arguments[0] + "?" + UrlAddPara + "&id=-1&tmp=" + (new Date).getTime() : FileUrl + "?" + UrlAddPara + "&id=-1&tmp=" + (new Date).getTime(), NewWindow ? "undefined" != typeof parent.AddWin ? parent.AddWin(e, AddText) : "undefined" != typeof parent.parent.AddWin ? parent.parent.AddWin(e, AddText) : location.href = e : ShowModalUrl("popEdit", e, AddText, PromptInfo, PopEditWidth, PopEditHeight)
}
function edit() {
    var e = $("#dgrid .GridViewFocus").attr("keyValue"), d = EditText + $("#dgrid .GridViewFocus").attr("title");
    if (e) {
        var i = $("#dgrid .GridViewFocus").attr("keyCode"), t = FileUrl + "?" + UrlEditPara + "&id=" + e + "&keyCode=" + i + "&tmp=" + (new Date).getTime();
        "id" != KeyFieldName && (t += "&" + KeyFieldName + "=" + e), NewWindow ? "undefined" != typeof parent.AddWin ? parent.AddWin(t, d) : "undefined" != typeof parent.parent.AddWin ? parent.parent.AddWin(t, d) : location.href = t : ShowModalUrl("popEdit", t, d, PromptInfo, PopEditWidth, PopEditHeight)
    } else alert("您没有选择一条记录！")
}
function SelectRow(e, d) {
    d.checked || $("#dgrid .GridViewHeader .GridViewCheckBox input").prop("checked", !1), d.checked ? $("#dgrid #GridViewRow_" + e).addClass("GridViewSelect") : $("#dgrid #GridViewRow_" + e).removeClass("GridViewSelect")
}
function SelectAllRows(e) {
    $("#dgrid .GridViewSelectCheckBox").prop("checked", e), e ? $("#dgrid .GridViewRow").addClass("GridViewSelect") : $("#dgrid .GridViewRow").removeClass("GridViewSelect")
}
function GoPage(e) {
    CurPage = e, $.ajax({
        type: "POST",
        url: DataPageUrl,
        data: {
            CurPage: CurPage,
            OrderField: OrderField,
            OrderType: OrderType,
            LocatePara: LocatePara,
            CustomPara: CustomPara,
            t: (new Date).getTime()
        },
        dataType: "html",
        success: function (e) {
            $("#dgrid").html(e), $("#DataPageHTML").html(SetPage(CurPage, RowCount, PageSize, 10, "GoPage")), $("#dgrid .GridViewRow").click(function () {
                $("#dgrid .GridViewRow").removeClass("GridViewFocus"), $(this).addClass("GridViewFocus"), GoSubPage()
            }), ($("#btn_browse").is(":visible") || $("#btn_mod").is(":visible")) && $("#dgrid .GridViewRow").dblclick(function () {
                edit()
            }), $("#dgrid .GridViewHeaderField font").click(function () {
                OrderField = $(this).parent().attr("id"), OrderType = 1 - OrderType, GoPage(CurPage)
            }), $("#dgrid .GridViewRow").eq(0).click(), TableColumnSize("dgridTb")
        }
    })
}
function GoSubPage() {
    if ("" != DataPageSubUrl) {
        var e = $("#dgrid .GridViewFocus").attr("keyValue");
        if (e) {
            var d = $("#dgrid .GridViewFocus").attr("keyCode");
            $.ajax({
                type: "POST",
                url: DataPageSubUrl,
                data: {id: e, keyCode: d, t: (new Date).getTime()},
                dataType: "html",
                success: function (e) {
                    $("#dgridSub").html(e), $("#dgridSub .GridViewRow").click(function () {
                        $("#dgridSub .GridViewRow").removeClass("GridViewFocus"), $(this).addClass("GridViewFocus")
                    })
                }
            })
        }
    }
}
function del(e) {
    var d = "";
    return $("#dgrid .GridViewCheckBox").is(":visible") ? $("#dgrid .GridViewSelectCheckBox:checked").each(function () {
        d += ",'" + $(this).val() + "'"
    }) : d = ",'" + $("#dgrid .GridViewFocus").attr("keyValue") + "'", "" == d ? void alert("你没有选择记录") : void(confirm(e) && (d = d.substring(1), $.ajax({
        type: "POST",
        url: DelUrl,
        data: {KeyValues: d, t: (new Date).getTime()},
        dataType: "json",
        success: function (e) {
            alert(e.message), "0000" == e.code && GoPage(CurPage)
        }
    })))
}
function Do(e, d) {
    $.ajax({
        type: "POST", url: e, data: d, dataType: "json", success: function (e) {
            alert(e.message), "0000" == e.code && GoPage(CurPage)
        }
    })
}
function importXls() {
    ShowModalUrl("popEdit", ImportUrl, ImportText, PromptInfo, 530, 300)
}
function exportXls() {
    var e = $("#frmExport");
    e && e.remove(), e = $("<form>"), e.attr("id", "frmExport"), e.attr("style", "display:none"), e.attr("target", ""), e.attr("method", "post"), e.attr("action", ExportUrl), $("body").append(e);
    var d = $("<input>");
    d.attr("type", "hidden"), d.attr("name", "OrderField"), d.attr("value", OrderField), e.append(d), d = $("<input>"), d.attr("type", "hidden"), d.attr("name", "OrderType"), d.attr("value", OrderType), e.append(d), d = $("<input>"), d.attr("type", "hidden"), d.attr("name", "LocatePara"), d.attr("value", LocatePara), e.append(d), e.submit()
}